package com.check;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;

public class Centos7Node16DockerBrowser {
    public static void main(String[] args) {
        System.setProperty("playwright.cli.dir", "/home/admin/playwright/cliDir");
        HashMap<String, String> envMap = new HashMap<>();
        envMap.put("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "true");
        envMap.put("PLAYWRIGHT_NODEJS_PATH", "/home/admin/.nvm/versions/node/v16.20.2/bin/node");
        try (Playwright playwright = Playwright.create(
                new Playwright.CreateOptions().setEnv(envMap))) {
            BrowserType chromiumType = playwright.chromium();
            String wsEndpoint = "ws://127.0.0.1:3000/";
            Browser browser = chromiumType.connect(wsEndpoint);
            Page page = browser.newPage();
            page.navigate("https://example.com");
            Path path = Paths.get("screenshot.png");
            page.screenshot(new Page.ScreenshotOptions()
                    .setPath(path)
                    .setFullPage(true));
        }
    }
}
